package com.ycz.zheng_springboot.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycz.zheng_springboot.entity.Files;
import com.ycz.zheng_springboot.mapper.FileMapper;
import com.ycz.zheng_springboot.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, Files> implements FileService {
    @Autowired
    private FileMapper fileMapper;

    /**
     * 通过文件的md5查询文件
     *
     * @param md5
     * @return
     */
    @Override
    public Files getFileByMd5(String md5) {
        // 查询文件的md5是否存在
        QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("md5", md5);
        List<Files> filesList = fileMapper.selectList(queryWrapper);// 查询文件
        return filesList.size() == 0 ? null : filesList.get(0);// 返回文件
    }
}
